All Questions
Tagged with c++object-oriented-design
102 questions
2votes
0answers
223views
How to encapsulate functions inside a library
I'm working on a project that uses an in-house library, which is also used by other projects. There are some classes and methods in other classes that are not used outside the library itself, is there ...
1vote
3answers
263views
How to allow users to provide their own child classes in a factory design pattern in c++?
I am building a c++ project that will allow users to essentially model and create their own fleet of cars. Right now, the approach I have in mind is a Car Factory Class that will implement all of the ...
0votes
2answers
174views
Designing a Two-Party Protocol
I want to design a two-party protocol that runs on two different processes; each process is one party of the protocol. My implementation of a Protocol looks as follows: enum class Role { P1, P2 }; ...
2votes
3answers
313views
Implementing factory that return the correct type
Imagine I have a factory that must create object based on unknown input (let's say user input). class Base; class MyFactory { static unique_ptr<Base> CreateBase(Input& input); } Now this ...
0votes
1answer
121views
Which approach do I choose for representing objects and scenes in my 3D drawing library?
I'm creating my own drawing library in C++ to provide shared rendering code for my projects. Since the library is designed to be used as a component of other projects, the renderer's representation of ...
1vote
2answers
278views
OOP Design of a Mathematical Group
A Group is formally defined as a set of Element's, over which a single operator mul is defined. There are different kinds of Groups, and each kind requires a different set of parameters. Operator mul ...
2votes
2answers
637views
Optimal way to share data between different classes
I have a C++ code that performs simulation of a physical system which deals with motion of objects. It has the following classes: Class Main, containing all the main calculation methods and the data ...
0votes
1answer
168views
Is it good practice for object APIs to be required to be called in sequence to gather information?
I had this discussion with someone and it ended ambiguously. Suppose you have a class that needs to Parse a file to gather some information. It can expose this information to you after the fact. ...
-3votes
1answer
206views
Should you default to using classes in C++? [duplicate]
I recently discovered the KISS and YAGNI principles which made me question my usage with classes because I use them constantly without really thinking about it and I realized my code could be much ...
1vote
0answers
129views
Refactoring code for template class
I have a template class in c++ that depends on a few nontype template parameters. The implementation of some methods, and some field member, depend on the value of the template parameters, in a ...
0votes
0answers
76views
Should I separate algorithms that rely on a data structure into different classes
I'm learning about graph algorithms, so to learn them better I'm beginning to write some of them using c++. For example, I created the code for implementing the Depth First Search algorithm. Here's ...
0votes
1answer
1kviews
Some approach or Design Pattern to implement same method different parameters of Interface class
I am using the Flyweight pattern to cache and reuse objects of the different classes. For example, I have a Shape interface class and multiple types of Shapes implementing the methods from the ...
1vote
0answers
507views
Avoiding forward declaration and circular reference in C++
Consider a card game (something like Magic or Legends of Runeterra) program, with BaseCard, Deck and GameState classes/structs. The way I've conceptualized the relationship between these classes would ...
0votes
1answer
2kviews
is there a two-way (bidirectional) observer pattern?
I have two classes. "System" and "Bluetooth". I want to have a really loose coherency between these two classes as they should be able to exist or not without depending on each ...
2votes
1answer
424views
Difference between `Class.X` and `Class.getX()`?
Might be a silly question or something I might have just messed up in my head but here we go... I saw a code example of someone using getPos() in their own class to retrieve the current position of an ...